#ifndef __BALLADE_CLIENT_H__
#define __BALLADE_CLIENT_H__

#pragma once

#include <ballade/network.h>

#include <ballade/smartclient/config.h>
#include <ballade/smartclient/dispatcher.h>
#include <ballade/smartclient/header_creater.h>
#include <ballade/smartclient/listener.h>
#include <ballade/smartclient/reader_thread.h>

namespace Ballade
{
	namespace SmartClient
	{
		class SMARTCLIENT_API Client
		{
		public:
			Client();
			Client(const char *ipaddr, const unsigned short port);

			void setIPAddress(const char *ipaddr);
			void setPort(const unsigned short port);
			const char *getIPAddress() const;
			const unsigned short& getPort() const;

			void connect() throw (Network::SocketError);
			void connect(const char *ipaddr, const unsigned short port) throw (Network::SocketError);
			void close();

			const bool isConnected() const;

			void send(const char *name, const void *data) throw (Network::SocketError);
			
			void addListener(Listener *listener);
			void setHeaderCreater(HeaderCreater *creater);

		protected:
			void startReaderThread();
			void stopReaderThread();

		private:
			Network::Socket _socket;
			Dispatcher _dipatcher;
			ReaderThread *_readerThread;

			HeaderCreater *_headerCreater;

			void initialize(const char *ipaddr, const unsigned short port);
		};
	}
}

#endif